package com.fcdream.brpg;

import com.fcdream.brpg.weixin.WeixinApiController;
import com.fcdream.brpg.weixin.WeixinMsgController;
import com.jfinal.config.*;
import com.jfinal.kit.PropKit;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.activerecord.dialect.Sqlite3Dialect;
import com.jfinal.plugin.c3p0.C3p0Plugin;

/**
 * Created by shmdu on 2016/6/12. useradmin qhhsi
 * 171.217.42.179:55550
 */
public class BrpgConfig extends JFinalConfig {
    @Override
    public void configConstant(Constants me) {
        loadPropertyFile("a_little_config.txt");
        me.setDevMode(true);
    }

    @Override
    public void configRoute(Routes me) {
        me.add("/hello", HelloController.class);
        me.add("/", IndexController.class);
        me.add("/msg", WeixinMsgController.class);
        me.add("/api", WeixinApiController.class, "/api");
//        me.add("/weixin", )
    }

    @Override
    public void configPlugin(Plugins me) {
        // 配置C3p0数据库连接池插件
        C3p0Plugin c3p0Plugin = new C3p0Plugin(getProperty("jdbcUrl"), getProperty("user"), getProperty("password"));
        c3p0Plugin.setDriverClass("org.sqlite.JDBC"); //指定驱动程序
        me.add(c3p0Plugin);
        // 配置ActiveRecord插件
        ActiveRecordPlugin arp = new ActiveRecordPlugin(c3p0Plugin);
        me.add(arp);
        arp.setDialect(new Sqlite3Dialect());  //指定 Dialect

    }

    @Override
    public void configInterceptor(Interceptors me) {

    }

    @Override
    public void configHandler(Handlers me) {

    }

    public static C3p0Plugin createC3p0Plugin() {
        C3p0Plugin c3p0Plugin = new C3p0Plugin(PropKit.get("jdbcUrl"), PropKit.get("user"), PropKit.get("password").trim());
        c3p0Plugin.setDriverClass("org.sqlite.JDBC");
        return c3p0Plugin;
    }
}
